"""
@File    : read_ini.py
@Author  : qve-wzy
@Time    : 2020/9/2 0002 15:19
"""
import configparser

class ReadIni:
	'''
	读取ini数据
	'''
	def __init__(self,file_path=None):
		if file_path == None:
			self.file_path = 'C:/Users/Administrator/PycharmProjects/appnium-test/config/localElement.ini'
		else:
			self.file_path = file_path
		self.data = self.read_ini()

	def read_ini(self):
		read_ini = configparser.ConfigParser()
		read_ini.read(self.file_path)
		return read_ini

	#通过key获取对应的value
	def get_value(self,key,section=None):
		if section == None:
			section = 'login_element'
		try:
			value = self.data.get(section,key)
		except:
			value = None
		print("读取ini获得的值为:",value)
		return value

if __name__ == '__main__':
	read_ini = ReadIni()
	print(read_ini.get_value("username","login_element"))
	print(read_ini.read_ini())